package lambda;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 集合转map
 * LocalDate:2023-07-25
 * LocalDateTime:2023-07-25T18:07:50.286
 * LocalTime:18:07:50.287
 */
public class Lambda1 {
    public static void main(String[] args) {
        List<Bird> birds = Arrays.asList(new Bird(12, 35), new Bird(12, 57), new Bird(165, 478),new Bird(12,89));
        // 如果key相同则value值相加
        Map<Integer, Integer> collect = birds.stream().collect(Collectors.toMap(Bird::getAge, Bird::getTail, (v1, v2) -> v2+v1));
        System.out.println(collect);
        // Duplicate key 35
//        Map<Integer, Integer> collect1 = birds.stream().collect(Collectors.toMap(Bird::getAge, Bird::getTail));
//        System.out.println(collect1);

        // 创建LinkedHashMap
        LinkedHashMap<Integer, Integer> collect1 = birds.stream().collect(Collectors.toMap(Bird::getAge, Bird::getTail, (v1, v2) -> v2 + v1, LinkedHashMap::new));
        System.out.println(collect1);

        System.out.println(LocalDate.now());
        System.out.println(LocalDateTime.now());
        System.out.println(LocalTime.now());
    }
}
